package com.konke.sdslibrary.model;

import com.sds.sdk.android.sh.common.SHDeviceSubType;
import com.sds.sdk.android.sh.common.SHDeviceType;

/**
 * 统一设备类型格式描述：物理设备、zigbee子类型设备、逻辑虚拟设备等等
 */
public enum UniformDeviceType {

    UNKNOWN,
    ZIGBEE_UNKOWN,
    ZIGBEE_LIGHT,
    ZIGBEE_SOCKET,
    ZIGBEE_CURTAIN,
    ZIGBEE_DooYa,
    ZIGBEE_RollingGate,
    ZIGBEE_WindowPusher,
    ZIGBEE_SCREEN,
    ZIGBEE_DriveAirer,              //晾衣架
    ZIGBEE_FloorHeating,
    ZIGBEE_FreshAir,
    ZIGBEE_ChopinFreshAir,          //肖邦新风
    ZIGBEE_FanCoil,
    ZIGBEE_TempSensor,
    ZIGBEE_HumiSensor,               //  湿度
    ZIGBEE_IllumSensor,              //  光照
    ZIGBEE_CO2Sensor,
    ZIGBEE_FormalSensor,             //  甲烷
    ZIGBEE_PM25Sensor,
    ZIGBEE_DimmerLight,
    ZIGBEE_DimmerRGB,
    ZIGBEE_DimmerZerofireWire,
    ZIGBEE_DimmerZerofireWire_2G,
    ZIGBEE_DimmerSinglefireWire,        //灯光面板
    ZIGBEE_DimmerKKRGB,
    ZIGBEE_DimmerRGBW,
    ZIGBEE_Infrared,
    ZIGBEE_InfraredCodeLib,
    ZIGBEE_RFTransmitter,
    ZIGBEE_DoorContact,
    ZIGBEE_ScenePanel,
    ZIGBEE_SOSPanel,
    ZIGBEE_SOSButton,
    ZIGBEE_ShortcutPanel,
    ZIGBEE_Lock800,                    //门锁
    ZIGBEE_KonkeLock,
    ZIGBEE_CodedLock,                 //密码锁
    ZIGBEE_KonkeSocket,
    ZIGBEE_ExtensionSocket,
    ZIGBEE_Socket10A,
    ZIGBEE_Socket16A,
    ZIGBEE_433GuardSensorBool,
    ZIGBEE_433GuardAlertor,
    ZIGBEE_433GuardRemoteController,
    ZIGBEE_Alertor,                    //报警器
    ZIGBEE_HumanbodyInfraredSensor,    //人体红外
    ZIGBEE_SmokeSensor,                //烟感
    ZIGBEE_GasSensor,
    ZIGBEE_WaterSensor,
    ZIGBEE_UniversalSensor,
    ZIGBEE_CentralAC_Gateway,
    ZIGBEE_ElectricalEnergyMeter,      // 电能表
    ZIGBEE_AirSwitchManager,           //空开管理器
    ZIGBEE_AirSwitch,                   //空开
    ZIGBEE_FloorHeatingManager,         //地暖网关
    ZIGBEE_FloorHeatingDev,
    ZIGBEE_WaterValueSwitch,            //水阀
    ZIGBEE_FreshAirManager,             //新风网关
    ZIGBEE_FreshAirDev,
    NET_JuFengIpc,
    NET_HueLight,
    NET_KonkeSocket,
    NET_KonkeLight,
    NET_KonkeHumidifier,                //加湿器
    NET_KonkeAircleaner,                //净化器
    NET_EZCamera,
    NET_EquesDoorbell,                  //可视门铃
    NET_WeijuDevice,
    NET_CnwiseMusicController,          // 音乐主机
    NET_YouzhuanMusicController,
    NET_ModBusDevice,
    NET_CENTRAL_AC_Gateway,             //空调网关
    NET_CENTRAL_AC_IndoorUnit,
    NET_DaikinIndoorUnit,
    NET_Kit,
    NET_AIR_BOX,                        //空气质量盒子
    VIRTUAL_SOS_SYSTEM,
    VIRTUAL_ZONE_LIGHT,
    VIRTUAL_ZONE_CURTAIN,
    VIRTUAL_ZONE_AC,
    VIRTUAL_ROBOT_VOICE,
    VIRTUAL_SCENE,
    VIRTUAL_IFTTT_RULE,
    VIRTUAL_GUARD_SYSTEM;

    public static UniformDeviceType transform(SHDeviceType type, SHDeviceSubType subType) {
        if (subType != null && subType != SHDeviceSubType.UNKOWN) {
            return parseSubType(subType);

        } else if (subType != null && type != SHDeviceType.UNKOWN) {
            return parseType(type);
        }
        return UNKNOWN;
    }

    public SHDeviceType parseSHDeviceType() {
        return SHDeviceType.parseValue(this.name());
    }

    public boolean isBoolSensor() {
        if (this.equals(ZIGBEE_DoorContact)
                || this.equals(ZIGBEE_HumanbodyInfraredSensor)
                || this.equals(ZIGBEE_SmokeSensor)
                || this.equals(ZIGBEE_GasSensor)
                || this.equals(ZIGBEE_WaterSensor)
                || this.equals(ZIGBEE_UniversalSensor)
                )
            return true;

        return false;
    }

    public boolean isNumSensor() {
        if (this.equals(ZIGBEE_TempSensor)
                || this.equals(ZIGBEE_HumiSensor)
                || this.equals(ZIGBEE_IllumSensor)
                || this.equals(ZIGBEE_CO2Sensor)
                || this.equals(ZIGBEE_FormalSensor)
                || this.equals(ZIGBEE_PM25Sensor))
            return true;

        return false;
    }

    public boolean isZigbee() {

        return this.name().startsWith("ZIGBEE_");
    }

    public boolean isZigbeeDimmer() {

        return this.name().startsWith("ZIGBEE_Dimmer");
    }

    private static UniformDeviceType parseType(SHDeviceType type) {
        try {
            return UniformDeviceType.valueOf(type.name());
        } catch (IllegalArgumentException e) {
        }
        return UNKNOWN;
    }

    private static UniformDeviceType parseSubType(SHDeviceSubType subType) {
        try {
            return UniformDeviceType.valueOf(subType.name());
        } catch (IllegalArgumentException e) {
        }
        return UNKNOWN;
    }
}
